package org.chibandroid.database;

import android.content.Context;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DatabaseHelper extends SQLiteOpenHelper {

	private String CREATE_TREASUREMASTER;
	private String CREATE_TREASUREHUNT;

	public DatabaseHelper(Context context) {
		super(context, "TreasureHunt", null, 1);

		CREATE_TREASUREMASTER = "CREATE TABLE TREASUREMASTER(";
		CREATE_TREASUREMASTER += "TREASURENAME   TEXT PRIMARY KEY,";
		CREATE_TREASUREMASTER += "SUCCESSCOMMENT TEXT";
		CREATE_TREASUREMASTER += ");";

		CREATE_TREASUREHUNT = "CREATE TABLE TREASUREHUNT(";
		CREATE_TREASUREHUNT += "TREASURENAME   TEXT,";
		CREATE_TREASUREHUNT += "TREASURESEQ    INTEGER,";
		CREATE_TREASUREHUNT += "HINT1          TEXT,";
		CREATE_TREASUREHUNT += "HINT2          TEXT,";
		CREATE_TREASUREHUNT += "HINT3          TEXT,";
		CREATE_TREASUREHUNT += "LATITUDE       INTEGER,";
		CREATE_TREASUREHUNT += "LONGITUDE      INTEGER,";
		CREATE_TREASUREHUNT += "CONSTRAINT PX_TREASURE PRIMARY KEY(TREASURENAME,TREASURESEQ));";

	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		db.beginTransaction();
		try {
			db.execSQL(CREATE_TREASUREMASTER);
			db.execSQL(CREATE_TREASUREHUNT);
			db.setTransactionSuccessful();
		}catch(SQLException e){
			e.printStackTrace();
		} finally {
			db.endTransaction();
		}
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

	}

}
